<?php
include_once("../service/CategoryService.php");
/**
 * @author Minh Luan
 * @copyright 2012
 */
if(isset($_POST['view_cat_id'])){
    $cat_id = $_POST['view_cat_id'];
    $categoryInfor = mysql_fetch_array(getCategory($cat_id));
    $cat_name_en = $_POST['cat_name_en'];
    $cat_name_vn = $_POST['cat_name_vn'];
    $description_en = $_POST['cat_description_en'];
    $description_vn = $_POST['cat_description_vn'];
    $cat_parent_id = $_POST["cat_parent_id"];
    
    updateCategory($cat_name_en, $cat_name_vn, $description_en, $description_vn, $cat_parent_id, $cat_id);
            if($_FILES['cat_image']['name'] != ''){
                //Image Chosen
                if ((($_FILES["cat_image"]["type"] == "image/gif") || ($_FILES["cat_image"]["type"] == "image/jpeg") || ($_FILES["cat_image"]["type"] == "image/jpg")) && ($_FILES["cat_image"]["size"] < 1048576))
                {
                    if ($_FILES["cat_image"]["error"] > 0)
                    {
                    echo "Return Code: " . $_FILES["cat_image"]["error"] . "<br />";
                    }
                    else
                    {
                      move_uploaded_file($_FILES["cat_image"]["tmp_name"],"../images/cat/CAT_".$cat_id.".jpg");
                    }
                    updateCategoryImageUrl($cat_id, "CAT_".$cat_id.".jpg");
                    echo "<script>location.href='../admin/category-detail.php?do=view&n=".$cat_id."&msg=6'</script>";
                }
                else
                {
                    echo "Invalid file";
                    //echo "Upload: " . $_FILES["cat_image"]["name"] . "<br />";
                    //echo "Type: " . $_FILES["cat_image"]["type"] . "<br />";
                    //echo "Size: " . ($_FILES["cat_image"]["size"] / 1024) . " Kb<br />";
                    //echo "Temp file: " . $_FILES["cat_image"]["tmp_name"] . "<br />";
                    echo "<script>location.href='../admin/category-detail.php?do=view&n=".$cat_id."&msg=7'</script>"; 
                }
            }else{
                echo "<script>location.href='../admin/category-detail.php?do=view&n=".$cat_id."&msg=6'</script>";
            }
}
else{
    
    echo "<script>location.href='../admin/category.php'</script>";
}

?>